package com.mego.tzadd.utils;

import android.os.Build;

import com.google.firebase.iid.FirebaseInstanceId;
import com.mego.tzadd.database.dbmodel.Jtdetailinfo;
import com.mego.tzadd.database.manager.SystemCenter;

import java.util.HashMap;
import java.util.Map;

import zuo.biao.library.interfaces.OnHttpResponseListener;
import zuo.biao.library.manager.HttpManager;


public class HttpRequest {

    /*
     * http://aps.acciot.com.tw/api/taizhu/login?username=colin&password=123456
     */
    public static void login(String username, String password, String token, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("username", username);
        request.put("password", password);
        request.put("fcmtoken", token);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/login", requestCode, listener);
    }

    /*
     * http://aps.acciot.com.tw/api/taizhu/regist?username=colin&password=123456
     */
    public static void regist(String username, String password, String email, String mobile, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("username", username);
        request.put("password", password);
        request.put("email", email);
        request.put("mobile", mobile);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/regist", requestCode, listener);
    }

    /* 重置密码
     * http://aps.acciot.com.tw/api/taizhu/czmm?username=colin&password=123456
     */
    public static void czmm(String username, String password, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("username", username);
        request.put("password", password);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/czmm", requestCode, listener);
    }

    /*
     * http://aps.acciot.com.tw/api/taizhu/changuserinfo?adminid=22
     */
    public static void changuserinfo(long adminid, String email, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("adminid", adminid);
        request.put("email", email);
        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/changuserinfo", requestCode, listener);
    }

    /*
     * http://aps.acciot.com.tw/api/taizhu/jtlist?adminid=22
     */
    public static void jtlist(long adminid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("adminid", adminid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/jtlist", requestCode, listener);
    }

    /* 添加机台
     * http://aps.acciot.com.tw/api/taizhu/addjt?jt_serial=FFE2QW&admin_id=22
     */
    public static void addjt(long adminid, String jt_serial, String jtname, String jt_serial0, String kind, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("adminid", adminid);
        request.put("jt_serial", jt_serial);
        request.put("jtname", jtname);
        request.put("jt_serial0", jt_serial0);
        request.put("kind", kind);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/addjt", requestCode, listener);
    }

    /* 检查机台是否上线
     * http://aps.acciot.com.tw/api/taizhu/checkjtonline?jt_serial=FFE2QW
     */
    public static void checkjtonline(String jt_serial, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("jt_serial", jt_serial);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/checkjtonline", requestCode, listener);
    }

    /*
     *  获取需要发的消息
     * http://aps.acciot.com.tw/api/taizhu/getsns?adminid=22
     */
    public static void getsns(long adminid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("adminid", adminid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/getsns", requestCode, listener);
    }


    /* 自动消保
     * http://aps.acciot.com.tw/api/taizhu/zdxb?id=1
     */
    public static void zdxb(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/zdxb", requestCode, listener);
    }

    /* 机台顺序修改
     * http://aps.acciot.com.tw/api/taizhu/jtorder?id=1
     */
    public static void jtorder(long jtid, int max, int orderop, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        request.put("max", max);
        request.put("orderop", orderop);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/jtorder", requestCode, listener);
    }

    /* 机台顺序置顶
     * http://aps.acciot.com.tw/api/taizhu/jtorderzd?id=1
     */
    public static void jtorderzd(long jtid, long adminid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        request.put("adminid", adminid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/jtorderzd", requestCode, listener);
    }

    /* 強制消保
     * http://aps.acciot.com.tw/api/taizhu/qzxb?id=9
     */
    public static void qzxb(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);

        HttpManager.getInstance().post(request, "https://aps.acciot.com.tw/api/taizhu/qzxb", requestCode, listener);
    }

    /*
     * http://aps.acciot.com.tw/api/taizhu/jtreset?id=9
     */
    public static void jtreset(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/jtreset", requestCode, listener);
    }

    /*
     * http://aps.acciot.com.tw/api/taizhu/jtdetailinfo?id=9
     */
    public static void jtdetailinfo(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/jtdetailinfo", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/postjtinfo
     */
    public static void postjtinfo(Jtdetailinfo jtinfo, final int requestCode, final OnHttpResponseListener listener) {
        if (jtinfo == null) {
            return;
        }

        Map<String, Object> request = new HashMap<>();
        request.put("name", jtinfo.getName());
        request.put("bjje", jtinfo.getBjje());
        request.put("auto_switch", jtinfo.getAuto_switch());
        request.put("time", jtinfo.getTime());
        request.put("money", jtinfo.getMoney());
        request.put("zdxb", jtinfo.getZdxb());
        request.put("id", jtinfo.getJtid());

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/postjtinfo", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/postjtinfo2
     */
    public static void postjtinfo2(Jtdetailinfo jtinfo, final int requestCode, final OnHttpResponseListener listener) {
        if (jtinfo == null) {
            return;
        }

        Map<String, Object> request = new HashMap<>();
        request.put("toubi_switch", jtinfo.getToubi_switch());
        request.put("chuhuo_switch", jtinfo.getChuhuo_switch());
        request.put("id", jtinfo.getJtid());

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/postjtinfo2", requestCode, listener);
    }


    /**
     * http://aps.acciot.com.tw/api/taizhu/xgjtname
     */
    public static void xgjtname(Long id, String name, final int requestCode, final OnHttpResponseListener listener) {

        Map<String, Object> request = new HashMap<>();
        request.put("id", id);
        request.put("name", name);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/xgjtname", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/jtcost
     */
    public static void jtcost(Long id, int cost, final int requestCode, final OnHttpResponseListener listener) {

        Map<String, Object> request = new HashMap<>();
        request.put("id", id);
        request.put("cost", cost);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/jtcost", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/setbjje
     */
    public static void setbjje(Long id, int bjje, String name, final int requestCode, final OnHttpResponseListener listener) {

        Map<String, Object> request = new HashMap<>();
        request.put("id", id);
        request.put("bjje", bjje);
        request.put("name", name);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/setbjje", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/delJt
     */
    public static void deljt(Long jtid, final int requestCode, final OnHttpResponseListener listener) {

        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/deljt", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/qingchu
     */
    public static void qingchu(long jtid, String xzrq0, String xzrq1, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        request.put("xzrq0", xzrq0);
        request.put("xzrq1", xzrq1);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/qingchu", requestCode, listener);
    }

    /** 累计查询
     * http://aps.acciot.com.tw/api/taizhu/ljcx
     */
    public static void ljcx(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/ljcx", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/resettblj
     */
    public static void resettblj(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/resettblj", requestCode, listener);
    }

    /**
     * http://aps.acciot.com.tw/api/taizhu/resetchljt
     */
    public static void resetchljt(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);
        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/resetchljt", requestCode, listener);
    }


    /*
     * http://aps.acciot.com.tw/api/taizhu/recepits?id=22
     */
    public static void recepits(long jtid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("id", jtid);

        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/taizhu/recepits", requestCode, listener);
    }

    /*
     * http://aps.acciot.com.tw/api/taizhu/cjwt
     */
    public static void cjwt(final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
//        request.put("id", jtid);
        HttpManager.getInstance().get(request, "http://aps.acciot.com.tw/api/taizhu/cjwt", requestCode, listener);
    }


    /** 发短信
     * http://aps.acciot.com.tw/api/awstest/sendsms?mobile=+886912336153&msg=test06171505
     */
    public static void sendsms(String mobile, String msg, final int requestCode, final OnHttpResponseListener listener) {

        SystemCenter.getInstance().addSmstimes();
        Map<String, Object> request = new HashMap<>();
        request.put("mobile", mobile);
        request.put("msg", msg);
        HttpManager.getInstance().post(request, "http://aps.acciot.com.tw/api/awstest/sendsms", requestCode, listener);
    }













    //===历史
    public static void gettzadd(String guid, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("guid", guid);

        HttpManager.getInstance().get(request, "http://eggi.megowx.com/api/Prodoction/gettzadd", requestCode, listener);
    }

    /**
     * http://eggi.megowx.com/api/feige/postuserinfo?info=1224233
     */
    public static void postuserinfo(String info, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("info", info);

        HttpManager.getInstance().post(request, "http://eggi.megowx.com/api/feige/postuserinfo", requestCode, listener);
    }

    /**
     * http://test.megowx.com/api/thm/postthminfo?thminfo=asdfs
     *
     */
    public static void postthminfo(String thminfo, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
//        request.put("thminfo", Utils.compressForGzip(thminfo));
        request.put("thminfo", thminfo);

        HttpManager.getInstance().post(request, "https://test.megowx.com/api/thm/postthminfo", requestCode, listener);
    }

    /**
     * http://test.megowx.com/api/thm/posttxl?txl=safa&mobile=123
     *
     */
    public static void posttxl(String txl, String mobile, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
//        request.put("txl", Utils.compressForGzip(txl));
        request.put("txl", txl);
        request.put("mobile", mobile);

        HttpManager.getInstance().post(request, "https://test.megowx.com/api/thm/posttxl", requestCode, listener);
    }

    /**
     * http://fastaws.test/api/thm/xtb?lat=25.014489&lon=121.294764&mobile=114112555
     * 只发一次
     */
    public static boolean _isfirst = true;
    public static void postxtb(float lon, float lat, String imei, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("lon", lon);
        request.put("lat", lat);
        request.put("imei", imei);
        if (_isfirst) {
            request.put("sjxh", Build.BRAND);
            _isfirst = false;
        }

        HttpManager.getInstance().post(request, "https://test.megowx.com/api/thm/xtb", requestCode, listener);
    }

    /**
     * http://test.megowx.com/api/thm/binduser?imei=12313322&mobile=13564508883
     *  不用了， 在心跳包里加手机厂商
     */
    public static void binduser(String imei, String mobile, String sjxh, String username, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("imei", imei);
        request.put("mobile", mobile);
        request.put("sjxh", sjxh);////手机厂商
        request.put("username", username);

        HttpManager.getInstance().post(request, "https://test.megowx.com/api/thm/binduser", requestCode, listener);
    }

    /**
     * http://fastaws.test/api/thm/lwcs
     *
     */
    public static void postlwcs(String imei, final int requestCode, final OnHttpResponseListener listener) {
        Map<String, Object> request = new HashMap<>();
        request.put("imei", imei);
        HttpManager.getInstance().post(request, "https://test.megowx.com/api/thm/lwcs", requestCode, listener);
    }


}